<template>
	<view>
		<view v-if="!isSearch" class="content">
			<view class="left" @click="clickLeft">
				<image :src="friend.avatarUrl" mode="widthFix" lazy-load></image>
				<view class="iconfont sex-icon" :class="{'icon-nv': friend.sex == 1, 'icon-nan' : friend.sex == 2}"></view>
			</view>
			<view class="right" @click="clickRight">
				<view class="nick-name-wrap">
					<view class="nickname">{{friend.friendName ? friend.friendName : friend.nickName}}</view>
					<view class="uid">( {{friend.uid}} )</view>
				</view>
				<view class="email" v-if="showEmail && friend.email">
					<text class="iconfont icon-youjian email-icon"></text>
					<text class="email-text">{{friend.email}}</text>
				</view>
				<view class="motto">[个性签]: {{friend.motto ? friend.motto : '这个人很懒，什么都没留下！'}}</view>
			</view>
		</view>
		<view v-else class="content">
			<view class="left" @click="clickLeft">
				<image :src="friend.avatarUrl" mode="widthFix" lazy-load></image>
				<view class="iconfont sex-icon" :class="{'icon-nv': friend.sex == 1, 'icon-nan' : friend.sex == 2}"></view>
			</view>
			<view class="right" @click="clickRight">
				<view class="nick-name-wrap">
					<view class="nickname" v-if="!issearchAll" v-html="keywords(friend.friendName)"></view>
					<view class="nickname" v-if="issearchAll" v-html="keywords(friend.nickName)"></view>
					<view class="uid" 
					v-if="keywords(friend.uid) != friend.uid" 
					v-html="'( ' + keywords(friend.uid) + ' )'"></view>
					<view class="uid" 
					v-if="keywords(friend.email) != friend.email" 
					v-html="'( ' + keywords(friend.email) + ' )'"></view>
					<view class="uid" 
					v-if="keywords(friend.nickName) != friend.nickName && !issearchAll" 
					v-html="'( ' + keywords(friend.nickName) + ' )'"></view>
				</view>
				<view class="motto">[个性签]: {{friend.motto ? friend.motto : '这个人很懒，什么都没留下！'}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"funFriendItem",
		data() {
			return {

			};
		},
		props:{
			friend:{
				type:Object,
				default:function(){
					return {}
				}
			},
			showEmail:{
				type:Boolean,
				default:false
			},
			searchValue:{
				type:String,
				default:""
			},
			isSearch:{
				type:Boolean,
				default: false
			},
			issearchAll:{
				type:Boolean,
				default: false
			}
		},
		created() {
		},
		methods:{
			keywords(e){
				if(!e){
					return e
				}
				return e.replace(this.searchValue, `<text class="keyword">${this.searchValue}</text>`)
			},
			clickLeft(){
				this.$emit("clickLeft",this.friend.uid)
			},
			clickRight(){
				this.$emit("clickRight",this.friend.uid)
			}
		}
	}
</script>

<style>
	
	.keyword{
		color: #4B95F7;
	}
</style>
<style lang="scss" scoped>
	.content{
		padding: 15rpx 10rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		.left{
			position: relative;
			image{
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
			}
			.sex-icon{
				width: 40rpx;
				height: 40rpx;
				border-radius: 50%;
				position: absolute;
				bottom: -5rpx;
				left: 50%;
				transform: translateX(-50%);
				font-size: 26rpx;
				text-align: center;
				line-height: 40rpx;
				color: #FFF;
			}
			.icon-nan{
				background-color: #3a86ff;
			}
			.icon-nv{
				background-color: #FF3F98;
			}
		}
		.right{
			margin-left: 20rpx;
			.nick-name-wrap{
				display: flex;
				align-items: center;
				.uid{
					margin-left: 10rpx;
				}
			}
			.email{
				display: flex;
				align-items: center;
				.email-text{
					margin-left: 10rpx;
				}
			}
			.email,.motto{
				font-size: 26rpx;
				color: #999999;
			}
		}
	}
</style>
